package cn.java78.springboot.myschool.service;


import cn.java78.springboot.myschool.dao.ExamDao;
import cn.java78.springboot.myschool.entity.ExamResult;
import cn.java78.springboot.myschool.entity.Student;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author oldliu
 * @since 1.0
 */
@Service
//@Scope("prototype")
@Transactional(readOnly = true,propagation = Propagation.REQUIRED,timeout = 100000)
public class ExamService {
    @Resource
    private ExamDao examDao;
    @Resource
    private StudentService studentService;

    public ExamService(){
        System.out.println("ExamService init ");
    }
    @Transactional(readOnly = false)
    public int add(ExamResult a){
        int r=examDao.add(a);
        if(a.getScore()>=85){
            Student stu=new Student();
            stu.setStuno(a.getStid());//学号
            stu.setTelephone("1888888888"+a.getId());
            studentService.update(stu);
        }
        return r;
    }
}
